/******************************************************************************
 * This file is part of libemb.
 *
 * libemb is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * libemb is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with libemb.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Project: Embedme
 * Author : FergusZeng
 * Email  : cblock@126.com
 * git	  : https://gitee.com/newgolo/embedme.git
 * Copyright 2014-2020 @ ShenZhen ,China
*******************************************************************************/
#ifndef __POLL_SET_H__
#define __POLL_SET_H__

#include "BaseType.h"
#include "DateTime.h"
#include <sys/epoll.h>

/**
 * @file Pollset.h
 * @brief IO复用/轮询
 */
namespace libemb{

/**
 * @class Pollset 
 * @brief IO复用/轮询集
 */
class Pollset{
DECL_CLASSNAME(Pollset)
public:
	static const int EventRead = 0; 
	static const int EventWrite = 1; 
public:
	Pollset();
	virtual ~Pollset();
    /**
     * @brief 打开复用集
     * @param maxEvents 
     * @param et 
     * @return true 
     * @return false 
     */
	bool open(int maxEvents,bool et=false);
    /**
     * @brief 关闭复用集
     * @param void
     */
	void close();
    /**
     * @brief 增加轮询事件
     * @param fd 
     * @param event 
     * @return true 
     * @return false 
     */
	bool addEvent(int fd, int event);
    /**
     * @brief 移除轮询事件
     * @param fd 
     * @param event 
     * @return true 
     * @return false 
     */
	bool removeEvent(int fd, int event);
    /**
     * @brief 等待事件
     * @param fdArray 
     * @param eventArray 
     * @param usTimeout 
     * @return int 
     */
	int waitEvent(IntArray& fdArray, IntArray& eventArray, int usTimeout);
private:
	int m_epfd{-1};
	int m_size{0};
	bool m_edgeTrig{false};
	struct epoll_event* m_events{NULL};
};

}
#endif
